#include "Client.h"
int main(int argc, char *argv[]){
    //./client 127.0.0.1 1234 
    ARGS_CHECK(argc, 3);
    int sockfd = SockfdCreate(argv[1], argv[2]);
    int epfd =epoll_create(1);
    struct epoll_event event, readyset;
    event.events = EPOLLIN;
    event.data.fd = STDIN_FILENO;
    epoll_ctl(epfd, EPOLL_CTL_ADD, STDIN_FILENO, &event);
    event.data.fd = sockfd;
    epoll_ctl(epfd, EPOLL_CTL_ADD, sockfd, &event);
    while(1){
        epoll_wait(epfd, &readyset, 1, -1);
        if(readyset.data.fd == STDIN_FILENO){
            char buf[LENGTH] = {0};
            read(STDIN_FILENO, buf, sizeof(buf));
            SendCommand(sockfd, buf);
        }else{
            if(RecvMsg(sockfd) == -1){
                printf("Server process exited.\n");
                break;
            }
        }
    }
    close(sockfd);
    return 0;
}
